#ifndef YEPXML_READER_HPP
#define YEPXML_READER_HPP

#include <istream>
#include <sstream>
#include <map>
#include "document.hpp"
namespace yxml
{
    using namespace std;

    /**
     * @brief Reads a document
     **/
    class Reader
    {
    public:
        Reader( istream& in );
        void read( Document& document );

        enum Policy
        {
            NOTHING,
            IGNORE_FIRST_EXTRA_SPACE,
            IGNORE_LAST_EXTRA_SPACES,
            IGNORE_IDENTATION,
            IGNORE_ALL_EXTRA_SPACES,
        };

        /**
         * @brief Returns the textPolicy
         **/
        Policy textPolicy( void ) const
        {
            return _textPolicy;
        }

        /**
         * @brief Changes the textPolicy
         **/
        void textPolicy( Policy value )
        {
            _textPolicy = value;
        }

        /**
         * @brief Returns the commentPolicy
         **/
        Policy commentPolicy( void ) const
        {
            return _commentPolicy;
        }

        /**
         * @brief Changes the commentPolicy
         **/
        void commentPolicy( Policy value )
        {
            _commentPolicy = value;
        }


    private:
        string getTag( map<string,string> &attributes, bool& openning, bool& closing );
        string getComment();
        string getWord();
        string getText( const string& spaces );
        string getString();
        void match( char ch );
        string ignoreSpace();
        void readTag( Node& node );
        int get();
        void unget();
        bool eof();

        istream& _in;
        int _line;
        int _ccount;
        Policy _textPolicy;
        Policy _commentPolicy;
    };

}

#endif // YEPXML_READER_HPP
